package edu.nf.ch02.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * @author wangl
 * @date 2025/9/18
 */
@WebServlet(urlPatterns = "/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String user = req.getParameter("user");
        //将用户保存到HttpSession
        req.getSession().setAttribute("user", user);
        //转发到聊天页面
        req.getRequestDispatcher("/WEB-INF/chat.html").forward(req,resp);
    }
}